package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArtType;
import com.ruoyi.system.service.IArtTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 作品类型管理Controller
 * 
 * @author ruoyi
 * @date 2022-01-29
 */
@RestController
@RequestMapping("/system/type")
public class ArtTypeController extends BaseController
{
    @Autowired
    private IArtTypeService artTypeService;

    /**
     * 查询作品类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public AjaxResult list(ArtType artType)
    {
        List<ArtType> list = artTypeService.selectArtTypeList(artType);
        return AjaxResult.success(list);
    }

    /**
     * 导出作品类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "作品类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArtType artType)
    {
        List<ArtType> list = artTypeService.selectArtTypeList(artType);
        ExcelUtil<ArtType> util = new ExcelUtil<ArtType>(ArtType.class);
        util.exportExcel(response, list, "作品类型管理数据");
    }

    /**
     * 获取作品类型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return AjaxResult.success(artTypeService.selectArtTypeByTypeId(typeId));
    }

    /**
     * 新增作品类型管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "作品类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArtType artType)
    {
        return toAjax(artTypeService.insertArtType(artType));
    }

    /**
     * 修改作品类型管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "作品类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArtType artType)
    {
        return toAjax(artTypeService.updateArtType(artType));
    }

    /**
     * 删除作品类型管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "作品类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(artTypeService.deleteArtTypeByTypeIds(typeIds));
    }
}
